package com.kakarote.oa.controller;

import cn.hutool.core.util.StrUtil;
import com.kakarote.core.common.Result;
import com.kakarote.oa.entity.BO.OaFieldVerifyBO;
import com.kakarote.oa.entity.VO.OaLogTemplateFieldVO;
import com.kakarote.oa.service.IOaLogTemplateFieldService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wwl
 * @date 2022/7/5 17:27
 */
@RestController
@RequestMapping("/oaLogTemplateField")
@Api(tags = "日志模板字段")
public class OaLogTemplateFieldController {

    @Autowired
    private IOaLogTemplateFieldService oaLogTemplateFieldService;

    @PostMapping("/field/{logId}")
    @ApiOperation("查询新增所需字段")
    public Result<List> queryField(
            @PathVariable("logId") Long logId
            , @RequestParam("configId") Long configId
            , @RequestParam(value = "type", required = false) String type) {
        if (StrUtil.isNotEmpty(type)) {
            return Result.ok(oaLogTemplateFieldService.queryField(configId, logId));
        }
        return Result.ok(oaLogTemplateFieldService.queryFormPositionFieldVO(configId, logId));
    }

    @PostMapping("/field")
    @ApiOperation("查询新增所需字段")
    public Result<List> queryField(
            @RequestParam(value = "type", required = false) String type
            , @RequestParam("configId") Long configId) {
        if (StrUtil.isNotEmpty(type)) {
            return Result.ok(oaLogTemplateFieldService.queryField(configId, null));
        }
        return Result.ok(oaLogTemplateFieldService.queryFormPositionFieldVO(configId, null));
    }

    @PostMapping("/exportField/{configId}")
    @ApiOperation("查询导出的字段")
    public Result<List> queryExportField(@ApiParam("模板id") @PathVariable("configId") Long configId) {
        List<OaLogTemplateFieldVO> list = oaLogTemplateFieldService.queryExportFields(configId);
        return Result.ok(list);
    }

    @ApiOperation("验证字段是否存在")
    @PostMapping(value = "/verify")
    public Result<OaFieldVerifyBO> verify(@RequestBody OaFieldVerifyBO fieldVerifyBO) {
        OaFieldVerifyBO verify = oaLogTemplateFieldService.verify(fieldVerifyBO);
        return Result.ok(verify);
    }


}
